<template>
    <view class="uni-page-body">
        <popup-input ref='popupInput' @change="inputChange"></popup-input>
        <view class="">
            <view class="yc-li">
                <view class="yc-li-item" style="justify-content: space-between;font-size: 0.7em;">
                    <view class="" style="width: 60px;">
                        名称
                    </view>
                    <view class="" style="width: 60px;">
                        UID
                    </view>
                    <view class="" style="width: 60px;">
                        实名状态
                    </view>
                    <view class="" style="width: 60px;">
                        状态
                    </view>
                </view>
            </view>
            <scroll-view @scrolltolower="scrolltolower" scroll-y :style="'height:'+contentHeight+'px' " class="yc-ul">
                <view class="yc-li" v-for="(item,idx) in list" :key="item.id" style="white-space: nowrap;overflow-x: auto;">
                    <view class="yc-li-item" style="justify-content: space-between;font-size: 0.7em;" @tap="tapItem(item,idx)">
                        <view class="" style="width: 60px;white-space: nowrap;overflow: auto;">
                            <text v-if="item.realname">{{item.realname.name}}</text>
                            <text v-else-if="item.name">{{item.name}}</text>
                            <text v-else>未知</text>

                        </view>
                        <view class="" style="width: 60px;white-space: nowrap;overflow: auto;">
                            {{item.user_id}}
                        </view>
                        <view class="" style="width: 60px; text-align: center;">
                            <view class="" :style="item.state==1?'color: #09BB07;':'color: red;'">
                                {{item.state|state}}
                            </view>
                        </view>
                        <view class="" style="width: 60px; border-radius: 4px; text-align: center;">
                            <view class="" :style="item.action=='create'?'color: #09BB07;':'color: red;'">
                                {{item.action|action}}
                            </view>
                        </view>
                    </view>
                </view>
            </scroll-view>
        </view>

    </view>
</template>

<script>
    import area from '@/components/picker/city-data/area.js'
    import city from '@/components/picker/city-data/city.js'
    import province from '@/components/picker/city-data/province.js';
    import Request from '@/request/index.js'
    export default {
        components: {
            // popupInput
        },
        data() {

            var systemInfo = uni.getSystemInfoSync();

            return {
                p: 0,

                contentHeight: systemInfo.windowHeight - 80,

                list: [],

                form: null
            }
        },
        onLoad() {

        },
        filters: {
            action(e) {
                var arr = {
                    'create': '创建',
                    'update': '更新'
                }
                return arr[e] || '未知'
            },
            state(e) {
                // console.log(e)
                var arr = {
                    '0': '未实名',
                    '1': '已实名'
                }
                return arr[e] || '未知'
            }
        },
        computed: {

        },
        watch: {

        },
        onLoad() {
            this.getData()
        },
        methods: {
            inputChange(e) {
                console.log(e)
            },
            scrolltolower() {
                this.getData()
            },
            getData() {
                Request('UserAdminRealname_examineList', {
                    p: this.p
                }).then(e => {
                    console.log(e)
                    if (e.data.code == 200) {

                        var lst = this.list;
                        var newData = e.data.data;
                        try {
                            newData = newData.filter(e2 => {
                                e2.form = JSON.parse(e2.form)
                                return e2
                            })

                        } catch (e) {

                        }
                        var list = lst.concat(newData);
                        this.list = list;
                        this.p = this.p + 1;
                        if (newData.length < 10) {

                        }

                    }
                    // console.log(this.list)
                })
                console.log('获取数据')
                // 从服务器获取数据
                // var lst = this.list;


            },

            stateTabel(key) {
                if (key == 1) {
                    return '撤销删除'
                } else {
                    return '删除账号'
                }
            },
            tapExamine(item, idx) {

            },
            tapItem(item, idx) {
                uni.showActionSheet({
                    itemList: ['查看详情', '退回', '审核通过'],
                    success: (e) => {
                        console.log(e)
                        switch (e.tapIndex) {
                            case 0:
                                uni.navigateTo({
                                    url: "./detail?query=" + encodeURIComponent(JSON.stringify(item))
                                })
                                break;
                            case 1:
                                // console.log(e.tapIndex)
                                Request('UserAdminRealname_examine', {
                                    user_id: item.user_id,
                                    msg: '实名未通过'
                                }).then(e => {
                                    if (e.data.code == 200) {

                                        var list = this.list;

                                        this.list = list.filter((e, i) => {
                                            if (e.user_id != item.user_id) {
                                                return e
                                            }
                                        })
                                    } else {
                                        uni.showToast({
                                            title: e.data.message,
                                            icon: 'none'
                                        })
                                    }
                                })

                                break;
                            case 2:
                                //实名通过
                                Request('UserAdminRealname_examine', {
                                    user_id: item.user_id
                                }).then(e => {
                                    // console.log(e)
                                    if (e.data.code == 200) {

                                        var list = this.list;

                                        this.list = list.filter((e, i) => {
                                            if (e.user_id != item.user_id) {
                                                return e
                                            }
                                        })
                                    } else {
                                        uni.showToast({
                                            title: e.data.message,
                                            icon: 'none'
                                        })
                                    }

                                })
                                break;
                            default:
                                break;
                        }

                        // 

                    }
                })


            }

        }
    }
</script>

<style>

</style>
